kv tensor
KV-CAR: KV Cache Compression using Autoencoders and KV Reuse in Large Language Models
Roy, Sourjya, Sridharan, Shrihari, Selvam, Surya, Raghunathan, Anand
Abstract--As Large Language Models (LLMs) scale in size and context length, the memory requirements of the key-value (KV) cache have emerged as a major bottleneck during autoregressive decoding. The KV cache grows with sequence length and embedding dimension, often exceeding the memory footprint of the model itself and limiting achievable batch sizes and context windows. T o address this challenge, we present KV-CAR, a unified and architecture-agnostic framework that significantly reduces KV-cache storage while maintaining model fidelity. KV-CAR combines two complementary techniques. First, a lightweight autoencoder learns compact representations of key and value tensors along the embedding dimension, compressing them before they are stored in the KV cache and restoring them upon retrieval. Second, a similarity-driven reuse mechanism identifies opportunities to reuse KV tensors of specific attention heads across adjacent layers. T ogether, these methods reduce the dimensional and structural redundancy in KV tensors without requiring changes to the transformer architecture. Evaluations on GPT -2 and TinyLLaMA models across Wikitext, C4, PIQA, and Winogrande datasets demonstrate that KV-CAR achieves up to 47.85% KV-cache memory reduction with minimal impact on perplexity and zero-shot accuracy. System-level measurements on an NVIDIA A40 GPU show that the reduced KV footprint directly translates into longer sequence lengths and larger batch sizes during inference. Large Language Models (LLMs) have achieved remarkable performance across a wide range of natural language and multimodal tasks due to their ability to capture long-range dependencies and generate contextually rich outputs.
ALISA: Accelerating Large Language Model Inference via Sparsity-Aware KV Caching
Zhao, Youpeng, Wu, Di, Wang, Jun
The Transformer architecture has significantly advanced natural language processing (NLP) and has been foundational in developing large language models (LLMs) such as LLaMA and OPT, which have come to dominate a broad range of NLP tasks. Despite their superior accuracy, LLMs present unique challenges in practical inference, concerning the compute and memory-intensive nature. Thanks to the autoregressive characteristic of LLM inference, KV caching for the attention layers in Transformers can effectively accelerate LLM inference by substituting quadratic-complexity computation with linear-complexity memory accesses. Yet, this approach requires increasing memory as demand grows for processing longer sequences. The overhead leads to reduced throughput due to I/O bottlenecks and even out-of-memory errors, particularly on resource-constrained systems like a single commodity GPU. In this paper, we propose ALISA, a novel algorithm-system co-design solution to address the challenges imposed by KV caching. On the algorithm level, ALISA prioritizes tokens that are most important in generating a new token via a Sparse Window Attention (SWA) algorithm. SWA introduces high sparsity in attention layers and reduces the memory footprint of KV caching at negligible accuracy loss. On the system level, ALISA employs three-phase token-level dynamical scheduling and optimizes the trade-off between caching and recomputation, thus maximizing the overall performance in resource-constrained systems. In a single GPU-CPU system, we demonstrate that under varying workloads, ALISA improves the throughput of baseline systems such as FlexGen and vLLM by up to 3X and 1.9X, respectively.